package com.example.rabbitmqextension.config;

import com.example.rabbitmqextension.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class MQConfig {
    //消息确认(持久化)
    @Bean("ackQueue")
    public Queue ackQueue(){
        return QueueBuilder.durable(Constants.ACK_QUEUE).build();
    }

    @Bean("directExchange")
    public DirectExchange directExchange(){
        return ExchangeBuilder.directExchange(Constants.ACK_EXCHANGE).build();
    }
    @Bean("ackBinding")
    public Binding ackBinding(@Qualifier("directExchange") DirectExchange exchange, @Qualifier("ackQueue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("ack");
    }

    //非持久化
    @Bean("presQueue")
    public Queue presQueue(){
        return QueueBuilder.nonDurable(Constants.PRES_QUEUE).build();
    }
    @Bean("presExchange")
    public DirectExchange presExchange(){
        return ExchangeBuilder.directExchange(Constants.PRES_EXCHANGE).durable(false).build();
    }
    @Bean("presBinding")
    public Binding presBinding(@Qualifier("presQueue") Queue queue,@Qualifier("presExchange")DirectExchange presExchange){
        return BindingBuilder.bind(queue).to(presExchange).with("pres");
    }
}
